﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;
using Acms.AcmsControls;


public partial class Templates_ContactSales_Default : Acms.AcmsControls.TemplatePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataBind();
        }

    }

    public override void DataBind()
    {
        base.DataBind();
        var post = AcmsContext.CurrentPost;

        if (post != null)
        {
            //  var pnlItem = pnlItem;

            

            SetPopup(post, lnk1, 1);
            SetPopup(post, lnk2, 2);
            SetPopup(post, lnk3, 3);
            SetPopup(post, lnk4, 4);
            SetPopup(post, lnk5, 5);

        }
    }

    private void SetPopup(Post post, HyperLink lnk, int i)
    {
        if (post == null)
            throw new ArgumentNullException("post", string.Format("No post for index {0}", i));
        
        if (lnk == null)
            throw new ArgumentNullException("lnk", string.Format("No lnk for index {0}", i));
        //if (acmsTitle == null)
        //    throw new ArgumentNullException("acmsTitle", string.Format("No acmsTitle for index {0}", i));


        lnk.Visible = true;



        var title= (string)null;
        var popTitle = post.FindPostControl("Pop" + i + "_Title");
        if (popTitle != null)
        {
            var popTitleProperty = popTitle.GetProperties<Acms.AcmsControls.TextContentControlProperties>();
            if (popTitleProperty != null)
            {
                title= popTitleProperty.Text.Trim();
            }
        }


        
        var x = (string)null;
        var posX = post.FindPostControl("Pop" + i + "_X");
        if (posX != null)
        {
            var posXProperty = posX.GetProperties<Acms.AcmsControls.TextContentControlProperties>();
            if (posXProperty != null)
            {
                x = posXProperty.Text.Trim();
            }
        }

        var y = (string)null;
        var posY = post.FindPostControl("Pop" + i + "_Y");
        if (posY != null)
        {
            var posYProperty = posY.GetProperties<Acms.AcmsControls.TextContentControlProperties>();
            if (posYProperty != null)
            {
                y = posYProperty.Text.Trim();
            }
        }

        if (!string.IsNullOrEmpty(x) && !string.IsNullOrEmpty(y) &&!string.IsNullOrEmpty(title))
        {
            lnk.Style.Add("left", x + "px");
            lnk.Style.Add("top", y + "px");
            lnk.Text = title;
        }
        else
        {
            lnk.Visible = false;
        }
    }
}
